<?php
/**
 * Created by PhpStorm.
 * User: HP_USER
 * Date: 2018/9/13
 * Time: 13:55
 */

class Block{
    public $prevHash;//前一个区块的hash
    public $hash;//当前区块的hash
    public $timeStamp;//当前区块生成时间戳
    public $data;//区块保存的数据

    public function __construct($prevHash,$data)
    {
        $this->prevHash = $prevHash;
        $this->timeStamp = time();
        $this->data = $data;
        $this->setBlockHash();
    }


    public function setBlockHash()
    {
        $data=serialize($this);
        $this->hash = hash('sha256', $data);
    }

    public function getBlockHash()
    {
        return $this->hash;
    }
}
